package com.hengpeng.itfin.persist.impl;

import java.util.Date;
import java.util.List;

import org.springframework.stereotype.Repository;

import com.hengpeng.common.persist.AbstractDao;
import com.hengpeng.common.persist.query.DynamicQuery;
import com.hengpeng.common.persist.query.constants.QueryConstants.QueryType;
import com.hengpeng.itfin.persist.RewardAddRateDao;
import com.hengpeng.itfinbase.en.RewardAddRateStatus;
import com.hengpeng.itfinbase.persist.RewardAddRate;

@Repository
public class RewardAddRateDaoImpl extends AbstractDao<RewardAddRate> implements RewardAddRateDao {

    @Override
    public List<RewardAddRate> findRewardAddRateByStatus(RewardAddRateStatus status, int fetchSize) {
        DynamicQuery query = new DynamicQuery(RewardAddRate.class);
        query.eq("status", status);
        query.isNotNull("payTime");
        query.le("payTime", new Date());
        query.setPageIndex(1);
        query.setPageSize(fetchSize);
        query.setQueryType(QueryType.JDBC);
        return super.findAllByDynamicQuery(query);
    }

    @Override
    public int updateStatus(long id, RewardAddRateStatus oldStatus, RewardAddRateStatus newStatus, Date updateTime) {
        return super.exeNamedQuery("rewardAddRate.updateStatus", new Object[] { newStatus, updateTime, id, oldStatus });
    }
}
